// import Vue from "vue";
// import Layout from "@/layout";
import { constantRoutes, asyncSCRoutes, asyncRoutes, asyncAdminRoutes, asyncMonitorRoutes, asyncSocialRoutes, asyncAgriculturalSocialRoutes } from "@/router";
// 获取组件的方法
// const _import = require("../../router/_import_" + process.env.NODE_ENV);

// function filterAsyncRouter(asyncRouterMap) {
//   // 遍历后台传来的路由字符串，转换为组件对象
//   const accessedRouters = asyncRouterMap.filter(route => {
//     if (route.component) {
//       if (route.component === "Layout") {
//         // Layout组件特殊处理
//         route.component = Layout;
//       } else {
//         route.component = _import(route.component);
//       }
//     }
//     if (route.children && route.children.length) {
//       route.children = filterAsyncRouter(route.children);
//     }
//     return true;
//   });

//   return accessedRouters;
// }adminRoutes

const state = {
  routes: [],
  addRoutes: [],
  scroutes: [],
  scaddRoutes: [],
  adminRoutes: [],
  adminaddroutes: [],
  monitorRoutes: [],
  monitoraddroutes: [],
  socialRoutes: [],
  socialaddroutes: [],
  agriculturalSocialRoutes: [],
  agriculturalSocialaddroutes: [],
};

const mutations = {
  SET_ROUTES: (state, routes) => {
    state.addRoutes = routes;
    state.routes = constantRoutes.concat(routes);
  },
  SET_SCROUTES: (state, routes) => {
    state.scaddRoutes = routes;
    state.scroutes = constantRoutes.concat(routes);
  },
  SET_ADMINROUTES: (state, routes) => {
    state.adminaddroutes = routes;
    state.adminRoutes = constantRoutes.concat(routes);
  },
  SET_MONITORROUTES: (state, routes) => {
    state.monitoraddroutes = routes;
    state.monitorRoutes = constantRoutes.concat(routes);
  },
  SET_SOCIALROUTES: (state, routes) => {
    state.socialRoutes = routes;
    state.socialaddroutes = constantRoutes.concat(routes);
  },
  SET_AGRICULTURALSOCIALROUTES: (state, routes) => {
    state.agriculturalSocialRoutes = routes;
    state.agriculturalSocialaddroutes = constantRoutes.concat(routes);
  },
};

const actions = {
  generateRoutes({ commit }) {
    return new Promise(resolve => {
      let accessedRoutes;
      accessedRoutes = asyncRoutes;
      commit("SET_ROUTES", accessedRoutes);
      resolve(accessedRoutes);
    });
  },
  geneSyRateRoutes({ commit }) {
    return new Promise(resolve => {
      let accessedRoutes;
      accessedRoutes = asyncSCRoutes;
      commit("SET_SCROUTES", accessedRoutes);
      resolve(accessedRoutes);
    });
  },
  geneAdminRateRoutes({ commit }) {
    return new Promise(resolve => {
      let accessedRoutes;
      accessedRoutes = asyncAdminRoutes;
      // console.log(accessedRoutes)
      commit("SET_ADMINROUTES", accessedRoutes);
      resolve(accessedRoutes);
    });
  },
  geneMonitorRateRoutes({ commit }) {
    return new Promise(resolve => {
      let accessedRoutes;
      accessedRoutes = asyncMonitorRoutes;
      // console.log(accessedRoutes)
      commit("SET_MONITORROUTES", accessedRoutes);
      resolve(accessedRoutes);
    });
  },
  geneSocialRateRoutes({ commit }) {
    return new Promise(resolve => {
      let accessedRoutes;
      accessedRoutes = asyncSocialRoutes;
      // console.log(accessedRoutes)
      commit("SET_SOCIALROUTES", accessedRoutes);
      resolve(accessedRoutes);
    });
  },
  geneAgriculturalSocialRateRoutes({ commit }) {
    return new Promise(resolve => {
      let accessedRoutes;
      accessedRoutes = asyncAgriculturalSocialRoutes;
      // console.log(accessedRoutes)
      commit("SET_AGRICULTURALSOCIALROUTES", accessedRoutes);
      resolve(accessedRoutes);
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
